﻿namespace Future.Web.Controllers.SysModule
{
    /// <summary>
    /// 角色控制器
    /// </summary>
    public class RoleController : AuthorizeController
    {
        private readonly IRoleBLL _roleBLL;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="roleBLL"></param>
        public RoleController(IRoleBLL roleBLL)
        {
            _roleBLL = roleBLL;
        }

        /// <summary>
        /// 添加角色包含菜单
        /// </summary>
        /// <param name="roleDto"></param>
        /// <returns></returns>

        [HttpPost]
        [Permission("system:role:add")]
        public bool Add(RoleInfoDto roleDto)
        {
            return _roleBLL.AddRoleInfo(roleDto);
        }

        /// <summary>
        /// 根据Id获取角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("{id}")]
        public RoleModel GetById(Guid id)
        {
            RoleModel roleModel = _roleBLL.GetById(id);
            return roleModel;
        }

        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<RoleModel> GetList()
        {
            List<RoleModel> roleModels = _roleBLL.GetList();
            return roleModels;
        }

        /// <summary>
        /// 更新角色信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [Permission("system:role:edit")]
        public bool Update(RoleInfoDto roleDto)
        {
            return _roleBLL.UpdateInfo(roleDto);
        }

        /// <summary>
        /// 更改角色状态
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        [HttpPut]
        public bool UpdateStatus(Guid roleId, bool status)
        {
            return _roleBLL.UpdateStatus(roleId, status);
        }

        /// <summary>
        /// 批量授权用户
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        public bool AuthUserList(RoleInfoDto roleInfoDto)
        {
            return _roleBLL.AuthUserList(roleInfoDto.RoleId, roleInfoDto.UserIds);
        }

        /// <summary>
        /// 批量取消授权
        /// </summary>
        /// <param name="roleInfoDto"></param>
        /// <returns></returns>
        [HttpPut]
        public bool CancelAuthUserList(RoleInfoDto roleInfoDto)
        {
            return _roleBLL.CancelAuthUserList(roleInfoDto.RoleId, roleInfoDto.UserIds);
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpDelete]
        [Permission("system:role:remove")]
        public bool DelList(List<Guid> ids)
        {
            return _roleBLL.DeleteByIds(ids);
        }

        /// <summary>
        /// 分页获取角色信息列表
        /// </summary>
        /// <param name="roleQueryDto"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        [HttpGet]
        [Permission("system:role:query")]
        public PageModel<RoleModel> PageList([FromQuery] RoleQueryDto roleQueryDto, [FromQuery] PageParModel page)
        {
            PageModel<RoleModel> result = _roleBLL.SelctPageList(roleQueryDto, page);
            return result;
        }
    }
}
